import java.util.*;

public class prog {
}
class Solution {








    public boolean buddyStrings(String s, String goal) {
        if(s.length()!=goal.length()){
            return false;
        }
        if(s.equals(goal)){
            Set<Character> set=new HashSet<>();
            for(int i=0;i<s.length();i++){
                if(set.contains(s.charAt(i))){
                    return true;
                }else{
                    set.add(s.charAt(i));
                }
            }
            return false;
        }
        int count=0;
        int pre=-1;
        int cur=-1;
        for(int i=0;i<s.length();i++){
            if(count>2){
                return false;
            }
            if(s.charAt(i)==goal.charAt(i)){
                continue;
            }else{
                count++;
                if(pre==-1){
                    pre=i;
                }else{
                    cur=i;
                }
            }
        }
        return count==2&&s.charAt(pre)==goal.charAt(cur)&&s.charAt(cur)==goal.charAt(pre);
    }









    public boolean isRectangleOverlap(int[] rec1, int[] rec2) {
        boolean x=!(rec1[2]<=rec2[0]||rec2[2]<=rec1[0]);
        boolean y=!(rec1[3]<=rec2[1]||rec2[3]<=rec1[1]);
        return x&&y;
    }







    public List<List<Integer>> largeGroupPositions(String s) {
        List<List<Integer>> list=new ArrayList<>();
        int sum=1;
        for(int i=0;i<s.length();i++){
            if(i==s.length()-1||s.charAt(i)!=s.charAt(i+1)){
                if(sum>2){
                    list.add(Arrays.asList(i-sum+1,i));
                }
                sum=1;
            }else{
                sum++;
            }
        }
        return list;
    }




    public List<List<Integer>> largeGroupPositionses(String s) {
        List<List<Integer>> list=new ArrayList<>();
        if(s.length() <3){
            return list;
        }
        int i=0;
        int j=1;
        int count=1;
        while(i<s.length()&&j<s.length()){
            char chi=s.charAt(i);
            char chj=s.charAt(j);
            if(chi!=chj){
                if(count>2){
                    List<Integer> tmp=new ArrayList<>();
                    tmp.add(i);
                    tmp.add(j-1);
                    list.add(tmp);
                }
                count=1;
                j++;
                i=j-1;
            }else if(chi==chj){
                count++;
                j++;
            }
            if(count>2&&j==s.length()){
                List<Integer> tmp=new ArrayList<>();
                tmp.add(i);
                tmp.add(j-1);
                list.add(tmp);
            }
        }
        return list;
    }










    public String mostCommonWord(String paragraph, String[] banned) {
        paragraph+=',';
        Set<String> set=new HashSet<>();
        Map<String,Integer> map=new HashMap<>();
        for(String s : banned){
            set.add(s);
        }
        StringBuilder sb=new StringBuilder();
        int answer_count=0;
        String answer="";
        for(char ch : paragraph.toCharArray()){
            if(Character.isLetter(ch)){
                sb.append(Character.toLowerCase(ch));
            }else if(sb.length()>0){
                String index=sb.toString();
                if(!set.contains(index)){
                    map.put(index,map.getOrDefault(index,0)+1);
                    if(map.get(index)>answer_count){
                        answer_count++;
                        answer=index;
                    }
                }
                sb=new StringBuilder();
            }
        }
        return answer;
    }






    public int[] numberOfLines(int[] widths, String s) {
        int row=1;
        int col=0;
        for(char ch : s.toCharArray()){
            int tmp=widths[ch-'a'];
            col+=tmp;
            if(col>100){
                row++;
                col=tmp;
            }
        }
        return new int[]{row,col};
    }








    public int findLengthOfLCIS(int[] nums) {
        if(nums==null||nums.length==0){
            return 0;
        }
        int max=1;
        int count=1;
        for(int i=0;i<nums.length-1;i++){
            if(nums[i]<nums[i+1]){
                count++;
            }else{
                count=1;
            }
            max=Math.max(count,max);
        }
        return max;
    }
}